#include <gtest/gtest.h>
#include <iostream>
#include <string>

#include "containers/os_map.h"
#include "containers/os_unordered_map.h"
TEST(os_memery_test_container, test_map)
{
    size_t init_total_memory = get_memery_manager()->get_total_memory();
    size_t init_cur_alloc = get_memery_manager()->get_current_allocated();
    size_t init_peak_alloc = get_memery_manager()->get_peak_allocated();
    size_t init_remaining = get_memery_manager()->get_remaining_memory();
    size_t init_total_alloc = get_memery_manager()->get_total_allocated();
    size_t init_total_dealloc = get_memery_manager()->get_total_deallocated();

    {
        os_map_init(int, std::string, map);
        size_t map_init_memory = get_memery_manager()->get_current_allocated();
        map[1] = "one";
        map[2] = "two";
        map[3] = "three";

        EXPECT_EQ(map.size(), 3);
        EXPECT_EQ(map[1], "one");
        EXPECT_EQ(map[2], "two");
        EXPECT_EQ(map[3], "three");

        EXPECT_GT(get_memery_manager()->get_current_allocated(), map_init_memory);
        EXPECT_GT(get_memery_manager()->get_total_allocated(), init_total_alloc);
        EXPECT_LT(get_memery_manager()->get_remaining_memory(), init_remaining);

        map.clear();
        EXPECT_EQ(get_memery_manager()->get_current_allocated(), map_init_memory);
    }

    EXPECT_EQ(get_memery_manager()->get_current_allocated(), init_cur_alloc);
    EXPECT_GT(get_memery_manager()->get_total_deallocated(), init_total_dealloc);
}

TEST(os_memery_test_container, test_unordered_map)
{
    size_t init_total_memory = get_memery_manager()->get_total_memory();
    size_t init_cur_alloc = get_memery_manager()->get_current_allocated();
    size_t init_peak_alloc = get_memery_manager()->get_peak_allocated();
    size_t init_remaining = get_memery_manager()->get_remaining_memory();
    size_t init_total_alloc = get_memery_manager()->get_total_allocated();
    size_t init_total_dealloc = get_memery_manager()->get_total_deallocated();

    {
        os_unordered_map_init(int, std::string, umap);
        size_t umap_init_memory = get_memery_manager()->get_current_allocated();
        umap[1] = "one";
        umap[2] = "two";
        umap[3] = "three";

        EXPECT_EQ(umap.size(), 3);
        EXPECT_EQ(umap[1], "one");
        EXPECT_EQ(umap[2], "two");
        EXPECT_EQ(umap[3], "three");

        EXPECT_GT(get_memery_manager()->get_current_allocated(), umap_init_memory);
        EXPECT_GT(get_memery_manager()->get_total_allocated(), init_total_alloc);
        EXPECT_LT(get_memery_manager()->get_remaining_memory(), init_remaining);

        umap.clear();
    }

    EXPECT_EQ(get_memery_manager()->get_current_allocated(), init_cur_alloc);
    EXPECT_GT(get_memery_manager()->get_total_deallocated(), init_total_dealloc);
}